package com.example.myhelloworld.client;

public class produceExercise {
	
	String userName;
	GreetingServiceAsync GSA;
	produceExercise(String uName, GreetingServiceAsync gsa){
		userName = uName;
		GSA = gsa;
	}
	
	
	public ExerciseClass exerciseFromString(String exNameAndArgument){
		ExerciseClass returnExercise = null;
		try {
			//this is where the magic happens...
			String[] twoparts = exNameAndArgument.split(":",2);
			String exerciseName = twoparts[0];
			//argument might be a test, then the split will result in more than two strings. 
			String exerciseArgument =twoparts[1]; //unsplit(twoparts);
			System.out.println("exercise name/Argument: " + exerciseName + "/" + exerciseArgument);

			//if another exercise of type ExerciseClass is to be added, just add it here as an if-else clause.
			if (exerciseName.equals("plusMinusDivTimes")){
				returnExercise = new plusMinusDivTimes(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("sudoku")){
				returnExercise = new sudoku(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("TextExercise")){
				returnExercise = new TextExercise(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("TestExercise")){
				returnExercise = new TestExercise(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("UserManagementExercise")){
				returnExercise = new UserManagementExercise(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("TestCreaterExercise")){
				returnExercise = new TestCreaterExercise(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("StatisticsExercise")){
				returnExercise = new StatisticsExercise(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("DropExercise")){
				returnExercise = new DropExercise(userName, exerciseArgument, GSA);
			}else if (exerciseName.equals("AddExercises")){
				returnExercise = new AddExercises(userName, exerciseArgument, GSA);
			}else  if (exerciseName.equals("AddExercise")){
				returnExercise = new AddExercises(userName, exerciseArgument, GSA);
			}else{
				returnExercise = null;
			}
			
		} catch(Exception e){
			System.out.println(e);
		}
		return returnExercise;
	}
	
}
